<template>
  <div>
    <input v-model.lazy="username" />
    <span>{{ msg }}</span>
  </div>
</template>

<script>
import axios from "axios";
export default {
  name: "App",
  data() {
    return {
      username: "",
      msg: "",
    };
  },
  // 侦听器函数，要写到 watch 里面。这是固定的
  watch: {
    // 被侦听的数据 (新的值, 原来的值) {  .......  }
    async username(val) {
      if (val === "") {
        this.msg = "";
        return;
      }
      const { data: res } = await axios.get(
        "http://www.itcbc.com:3006/api/finduser/" + val
      );
      this.msg = result.data.message;
    },
  },
};
</script>